﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Wormhole.UI.Application
{
	/// <summary>
	/// Interaction logic for Hero.xaml
	/// </summary>
	public partial class Hero : UserControl
	{
		#region Properties

		#region Details Dialog
		private CardDetails _detailsDialog;
		/// <summary>
		/// The dialog to display card details.
		/// </summary>
		public CardDetails DetailsDialog 
		{ 
			get
			{
				return this._detailsDialog;
			}

			set
			{
				if (this._detailsDialog != value)
				{
					this._detailsDialog = value;
					this.InttializeDetailsDialog();
				}
			}
		}
		#endregion

		#region Game
		private Engine.Game _game;
		/// <summary>
		/// The game engine object.
		/// </summary>
		public Engine.Game Game 
		{
			get
			{
				return this._game;
			}

			set
			{
				if (this._game != value)
				{
					this._game = value;
					this.InitializeGame();
				}
			}
		}
		#endregion

		#endregion

		#region Constructor
		/// <summary>
		/// Initialize a default instance of the class.
		/// </summary>
		public Hero()
		{
			InitializeComponent();
		}

		public Hero(Engine.Game game)
			: this()
		{
			this.Game = game;
		}
		#endregion

		#region Initialize Game
		/// <summary>
		/// Initlialize controls for the game.
		/// </summary>
		protected void InitializeGame()
		{
			if (this.Game != null)
			{
				// assign the player to the appropriate ui elements
				this.score.player1.Player = this.Game.Player1;
				this.score.player2.Player = this.Game.Player2;

				this.pile1.Player = this.Game.Player1;
				this.pile2.Player = this.Game.Player2;

				this.handCards.Player = this.Game.Player1;

				this.teamCards.Game = this.Game;
				this.teamCards.Player = this.Game.Player1;

				this.supportCards.Game = this.Game;
				this.supportCards.Player = this.Game.Player1;

				this.missionCards.Player = this.Game.Player1;

				this.failedMissions.Player = this.Game.Player1;

				this.eventCards.Player = this.Game.Player1;
				this.faceupObstacles.Player = this.Game.Player2;
				this.unassignedAdversaries.Player = this.Game.Player2;

				this.missionTotal.Game = this.Game;
				this.missionPower.Game = this.Game;
				this.userIput.Player = this.Game.Player1;
			}
		}
		#endregion

		#region Inttialize Details Dialog
		/// <summary>
		/// Initialze the details dialog.
		/// </summary>
		protected void InttializeDetailsDialog()
		{
			this.handCards.DetailsDialog = this.DetailsDialog;
			this.teamCards.DetailsDialog = this.DetailsDialog;
			this.supportCards.DetailsDialog = this.DetailsDialog;
			this.faceupObstacles.DetailsDialog = this.DetailsDialog;
			this.unassignedAdversaries.DetailsDialog = this.DetailsDialog;
			this.missionCards.DetailsDialog = this.DetailsDialog;
			this.failedMissions.DetailsDialog = this.DetailsDialog;
			this.eventCards.DetailsDialog = this.DetailsDialog;
		}
		#endregion
	}
}
